package com.project.controller;

import com.project.bean.UserBean;
import com.project.mapper.IUserMapper;
import com.project.service.IUserService;
import org.apache.catalina.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.lang.reflect.Field;
import java.time.LocalDate;
import java.util.Enumeration;

@RestController
public class UserController {
    //1）登陆，创建登陆页面。要求输入用户名和密码，完成登陆验证，成功向客户端输出登陆成功，失败向客户端输出登陆失败。
    //2）添加，创建添加页面。输入用户名、密码、等级、生日，完成添加。添加成功后，向客户端输出添加成功。

    @Autowired
    private IUserService service;

    @RequestMapping("login")
    public String login(String userName, String pwd) {
        UserBean user = service.login(userName, pwd);
        if (user == null) {
            return "登录失败";
        } else {
            return "登陆成功";
        }

    }

    @RequestMapping("addUser")
    public String addUser(UserBean user) {
        if (user.getUserName() != null & user.getPwd() != null & user.getGrade() != null & user.getBirthday() != null) {
            service.addUser(user);
            return "添加成功";
        }
        return "添加失败";
    }

}
